package com.kstech.mp3604.base

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.kstech.mp3604.base.Global.RunningStatus
import com.kstech.mp3604.ui.listener.AutoHYListener
import com.kstech.mp3604.ui.listener.DialogIpPortListener
import com.kstech.mp3604.ui.listener.LoginSetParamListener
import com.kstech.mp3604.utils.combineWith

/**
 * author: blankii
 * created on: 2025/3/20 17:08
 * description:
 */
class HomeViewModel : ViewModel() {
    lateinit var autoHYListener: AutoHYListener
    lateinit var loginSetParamListener: LoginSetParamListener

    lateinit var ipPortSettingListener: DialogIpPortListener

    //串口是否正在连接
//    var serialCommIsConnect = MutableLiveData<Boolean>()

    //socket是否正在连接
//    var socketCommIsConnect = MutableLiveData<Boolean>()

    val serialCommIsConnect: MutableLiveData<Boolean> = MutableLiveData(false)
    val socketCommIsConnect: MutableLiveData<Boolean> = MutableLiveData(false)

    val bothDevicesOnline = serialCommIsConnect.combineWith(socketCommIsConnect) { d1, d2 ->
        d1 == true && d2 == true
    }

//    val networkError = serialCommIsConnect.combineWith(socketCommIsConnect) { d1, d2 ->
//        d1 != true || d2 != true
//    }

    //数据初始化 受领任务后mStack被初始化
    var dataInit = MutableLiveData<Boolean>()

    //串口控制器 故障
    var serialIsFault = false
    //弹种类型序号 GlobalTypeNameArr顺序为准
//    var typeNameIndex: Int = 0

    /**
     * 有 无任务 状态标志符
     * true：正在执行任务
     * false：无任务
     */
    val isTasking = MutableLiveData<Boolean>()

    val device_posX = MutableLiveData<Long>()//mm
    val device_posY = MutableLiveData<Int>()//mm
    val device_posZ = MutableLiveData<Int>()//mm
    val device_weight = MutableLiveData<Int>()//kg
    val device_state = MutableLiveData<RunningStatus>()


    init {
        isTasking.value = false
        device_posX.value = -Global.PIANCHA.toLong()
        device_posY.value = Global.PIANCHA_Y.toInt()
        device_posZ.value = 0
        device_weight.value = 0
        device_state.value = RunningStatus.STANDBY
    }
}